package com.qut.graduate.busrtquery.ui.user;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.graphics.Color;
import android.os.CountDownTimer;
import android.support.design.widget.TextInputEditText;
import android.support.design.widget.TextInputLayout;
import android.support.v7.widget.Toolbar;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.TextView;

import com.makeramen.roundedimageview.RoundedImageView;
import com.mikepenz.google_material_typeface_library.GoogleMaterial;
import com.qut.graduate.busrtquery.BRTQConstant;
import com.qut.graduate.busrtquery.BaseActivity;
import com.qut.graduate.busrtquery.R;
import com.qut.graduate.busrtquery.bean.User;
import com.qut.graduate.busrtquery.presenter.LoginPresenter;
import com.qut.graduate.busrtquery.utils.common.FormatUtils;
import com.qut.graduate.busrtquery.utils.common.LogUtils;
import com.qut.graduate.busrtquery.utils.uiabout.StatusBarUtils;
import com.qut.graduate.busrtquery.utils.uiabout.ToastColorfulUtils;
import com.qut.graduate.busrtquery.view.WavePageView;

import cn.bmob.v3.BmobSMS;
import cn.bmob.v3.BmobUser;
import cn.bmob.v3.exception.BmobException;
import cn.bmob.v3.listener.QueryListener;
import cn.bmob.v3.listener.UpdateListener;
import top.wefor.circularanim.CircularAnim;

/**
 * 登录、注册、修改密码界面
 *
 * @Author WLL
 * @Time: 2019/3/25 21:49
 */
public class LoginActivity extends BaseActivity implements View.OnClickListener, View.OnFocusChangeListener {
    private static final String TAG = "LoginActivity";
    private LoginPresenter presenter;
    private int loginType;
    private String userStr;
    private String emailStr;
    private String pwdStr;
    private String resetPwd1Str;
    private String resetPwd2Str;
    private String phoneStr;
    private String codeStr;

    private Toolbar toolbar;
    private TextView toolbarTitle;
    private FrameLayout mLoginAnimHead;
    private WavePageView mLoginWaveView;
    private RoundedImageView mLoginAnimImage;
    private LinearLayout mLoginTopLayout;
    private Button mLoginChangePhoneBtn;
    private Button mLoginChangeEmailBtn;
    private LinearLayout mRegisterTopLayout;
    private Button mRegisterChangePhoneBtn;
    private Button mRegisterChangeEmailBtn;
    private LinearLayout mResetPwdTopLayout;
    private Button mResetPwdChangePhoneBtn;
    private Button mResetPwdChangeEmailBtn;
    private LinearLayout mPhoneCodeLayout;
    private LinearLayout mEmailUsernamePwdLayout;
    private TextInputLayout mEmailInput;
    private TextInputEditText mEmail;
    private TextInputLayout mUsernameInput;
    private TextInputEditText mUsername;
    private TextInputLayout mPasswordInput;
    private TextInputEditText mPassword;
    private TextInputEditText mPhone;
    private TextInputEditText mCode;
    private LinearLayout mResetPwdLayout;
    private TextInputLayout mResetPwdInput1;
    private TextInputEditText mResetPwd1;
    private TextInputLayout mResetPwdInput2;
    private TextInputEditText mResetPwd2;
    private ProgressBar mProgressbar;
    private Button mSendCodeBtn;
    private Button mLoginBtn;
    private Button mRegisterBtn;
    private Button mResetPwdSendMsgBtn;
    private Button mResetPwdSureBtn;
    private Button mChangeResetPwdBtn;
    private Button mChangeLoginBtn;
    private Button mChangeRegisterBtn;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_login;
    }

    @Override
    public void onResume() {
        super.onResume();
        updateNowTheme();
    }

    @SuppressLint("ResourceAsColor")
    private void updateNowTheme() {
        toolbar.setPopupTheme(getPopupToolbarStyle());
        toolbar.setBackgroundColor(getPrimaryColor());
        toolbar.setTitle("");
        mLoginAnimHead.setBackgroundColor(getPrimaryColor());
        StatusBarUtils.fullScreen(this);
        updateBarColor();
    }

    @Override
    protected void init() {
        presenter = new LoginPresenter(this);
        initView();
        initEvent();
    }

    @Override
    public void onClick(View view) {
        User user = BmobUser.getCurrentUser(User.class);
        switch (view.getId()) {
            case R.id.change_login_btn:
                loginType = BRTQConstant.LOGIN_LAYOUT_LOGIN;
                toggleType();
                break;
            case R.id.change_register_btn:
                loginType = BRTQConstant.LOGIN_LAYOUT_REGISTER;
                toggleType();
                break;
            case R.id.change_reset_pwd_btn:
                loginType = BRTQConstant.LOGIN_LAYOUT_RESET_PWD_PHONE;
                toggleType();
                break;
            case R.id.login_change_phone_btn:
                loginType = BRTQConstant.LOGIN_LAYOUT_LOGIN;
                toggleLogin();
                break;
            case R.id.login_change_email_btn:
                loginType = BRTQConstant.LOGIN_LAYOUT_LOGIN_EMAIL;
                toggleLogin();
                break;
            case R.id.register_change_phone_btn:
                loginType = BRTQConstant.LOGIN_LAYOUT_REGISTER;
                toggleRegister();
                break;
            case R.id.register_change_email_btn:
                loginType = BRTQConstant.LOGIN_LAYOUT_REGISTER_EMAIL;
                toggleRegister();
                break;
            case R.id.reset_pwd_change_phone_btn:
                loginType = BRTQConstant.LOGIN_LAYOUT_RESET_PWD_PHONE;
                toggleResetPwd();
                break;
            case R.id.reset_pwd_change_email_btn:
                loginType = BRTQConstant.LOGIN_LAYOUT_RESET_PWD_EMAIL;
                toggleResetPwd();
                break;
            case R.id.send_code_btn:
                if (FormatUtils.isPhone(phoneStr)) {
                    timer.start();
                    SendCode(phoneStr);
                    ToastColorfulUtils.info(phoneStr);
                }
                break;
            case R.id.login_btn:
                if (user != null) ToastColorfulUtils.info("用户已登录");
                else{
                    mLoginBtn.setVisibility(View.GONE);
                    mProgressbar.setVisibility(View.VISIBLE);
                    presenter.login(loginType, userStr, emailStr, pwdStr, mLoginBtn, mProgressbar);
                }
                break;
            case R.id.register_btn:
                if (user != null) ToastColorfulUtils.info("用户已登录");
                else{
                    mRegisterBtn.setVisibility(View.GONE);
                    mProgressbar.setVisibility(View.VISIBLE);
                    presenter.register(loginType, phoneStr, codeStr, emailStr, userStr, pwdStr, mRegisterBtn, mProgressbar);
                }
                break;
            case R.id.reset_pwd_send_msg_btn:
                if (loginType == BRTQConstant.LOGIN_LAYOUT_RESET_PWD_PHONE) {
                    if (user != null) resetPwdCheckCode(phoneStr, codeStr);
                    else ToastColorfulUtils.info("用户未登录,请先登录");
                } else {
                    presenter.resetPwdByEmail(emailStr);
                }
                break;
            case R.id.reset_pwd_sure_btn:
                if (!FormatUtils.isPassword(resetPwd1Str)) {
                    ToastColorfulUtils.info("密码格式错误");
                    return;
                } else if (!FormatUtils.isPassword(resetPwd2Str)) {
                    ToastColorfulUtils.info("确认密码格式错误");
                    return;
                } else if (!resetPwd1Str.equals(resetPwd2Str)) {
                    ToastColorfulUtils.info("密码和确认密码不一致");
                    return;
                } else if (FormatUtils.isPassword(resetPwd1Str) && FormatUtils.isPassword(resetPwd2Str) && resetPwd1Str.equals(resetPwd2Str)) {
                    presenter.resetPwdByPhone(resetPwd1Str);
                }
                break;
        }
    }

    private void initEvent() {
        toolbarTitle.setText(R.string.login);
        loginType = BRTQConstant.LOGIN_LAYOUT_LOGIN;
        mLoginChangePhoneBtn.setBackgroundResource(R.drawable.shape_btn_corners_5dp);

        toolbar.setNavigationIcon(getToolbarIcon(GoogleMaterial.Icon.gmd_arrow_back));
        toolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
                overridePendingTransition(R.anim.activity_screen_zoom_in, R.anim.activity_screen_zoom_out);
            }
        });

        final FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(150, 150);
        lp.gravity = Gravity.BOTTOM | Gravity.CENTER;
        mLoginWaveView.setOnWaveAnimationListener(new WavePageView.OnWaveAnimationListener() {
            @Override
            public void OnWaveAnimation(float y) {
                lp.setMargins(0, 0, 0, (int) y + 150);
                mLoginAnimImage.setLayoutParams(lp);
            }
        });

        presenter.SetOnRegisterListener(new LoginPresenter.OnRegisterListener() {
            @Override
            public void OnFinish() {
                CircularAnim.fullActivity(LoginActivity.this, mProgressbar)
                        .go(new CircularAnim.OnAnimationEndListener() {
                            @Override
                            public void onAnimationEnd() {
                                startActivity(new Intent(LoginActivity.this, UserCenterActivity.class));
                                finish();
                                overridePendingTransition(R.anim.activity_screen_zoom_in, R.anim.activity_screen_zoom_out);
                            }
                        });
            }

            @Override
            public void OnFail() {
            }
        });

        if (getIntent() != null && getIntent().getStringExtra("resetPassword") != null
                && getIntent().getStringExtra("resetPassword").equals("resetPassword")) {
            loginType = BRTQConstant.LOGIN_LAYOUT_RESET_PWD_PHONE;
            toggleType();
        }
    }

    @Override
    public void onFocusChange(View view, boolean hasFocus) {
        switch (view.getId()) {
            case R.id.password:

                break;
            case R.id.username:

                break;
        }
    }

    private void initView() {
        toolbar = findViewById(R.id.toolbar);
        toolbarTitle = findViewById(R.id.toolbar_title);
        setSupportActionBar(toolbar);
        mLoginAnimHead = findViewById(R.id.login_anim_head);
        mLoginWaveView = findViewById(R.id.login_wave_view);
        mLoginAnimImage = findViewById(R.id.login_anim_image);
        mLoginTopLayout = findViewById(R.id.login_top_layout);
        mLoginChangePhoneBtn = findViewById(R.id.login_change_phone_btn);
        mLoginChangeEmailBtn = findViewById(R.id.login_change_email_btn);
        mRegisterTopLayout = findViewById(R.id.register_top_layout);
        mRegisterChangePhoneBtn = findViewById(R.id.register_change_phone_btn);
        mRegisterChangeEmailBtn = findViewById(R.id.register_change_email_btn);
        mResetPwdTopLayout = findViewById(R.id.reset_pwd_top_layout);
        mResetPwdChangePhoneBtn = findViewById(R.id.reset_pwd_change_phone_btn);
        mResetPwdChangeEmailBtn = findViewById(R.id.reset_pwd_change_email_btn);
        mPhoneCodeLayout = findViewById(R.id.phone_code_layout);
        mPhone = findViewById(R.id.phone);
        mCode = findViewById(R.id.code);
        mEmailUsernamePwdLayout = findViewById(R.id.email_username_pwd_layout);
        mEmailInput = findViewById(R.id.email_input);
        mEmail = findViewById(R.id.email);
        mUsernameInput = findViewById(R.id.username_input);
        mUsername = findViewById(R.id.username);
        mPasswordInput = findViewById(R.id.password_input);
        mPassword = findViewById(R.id.password);
        mResetPwdLayout = findViewById(R.id.reset_password_layout);
        mResetPwdInput1 = findViewById(R.id.reset_password_input1);
        mResetPwd1 = findViewById(R.id.reset_password1);
        mResetPwdInput2 = findViewById(R.id.reset_password_input2);
        mResetPwd2 = findViewById(R.id.reset_password2);
        mProgressbar = findViewById(R.id.progressbar);
        mSendCodeBtn = findViewById(R.id.send_code_btn);
        mLoginBtn = findViewById(R.id.login_btn);
        mRegisterBtn = findViewById(R.id.register_btn);
        mResetPwdSendMsgBtn = findViewById(R.id.reset_pwd_send_msg_btn);
        mResetPwdSureBtn = findViewById(R.id.reset_pwd_sure_btn);
        mChangeLoginBtn = findViewById(R.id.change_login_btn);
        mChangeRegisterBtn = findViewById(R.id.change_register_btn);
        mChangeResetPwdBtn = findViewById(R.id.change_reset_pwd_btn);

        mLoginChangePhoneBtn.setOnClickListener(this);
        mLoginChangeEmailBtn.setOnClickListener(this);
        mRegisterChangePhoneBtn.setOnClickListener(this);
        mRegisterChangeEmailBtn.setOnClickListener(this);
        mResetPwdChangePhoneBtn.setOnClickListener(this);
        mResetPwdChangeEmailBtn.setOnClickListener(this);
        mSendCodeBtn.setOnClickListener(this);
        mLoginBtn.setOnClickListener(this);
        mRegisterBtn.setOnClickListener(this);
        mResetPwdSendMsgBtn.setOnClickListener(this);
        mResetPwdSureBtn.setOnClickListener(this);
        mChangeLoginBtn.setOnClickListener(this);
        mChangeRegisterBtn.setOnClickListener(this);
        mChangeResetPwdBtn.setOnClickListener(this);

        mUsername.addTextChangedListener(new TextChangeWatcher(mUsername));
        mPassword.addTextChangedListener(new TextChangeWatcher(mPassword));
        mResetPwd1.addTextChangedListener(new TextChangeWatcher(mResetPwd1));
        mResetPwd2.addTextChangedListener(new TextChangeWatcher(mResetPwd2));
        mPhone.addTextChangedListener(new TextChangeWatcher(mPhone));
        mCode.addTextChangedListener(new TextChangeWatcher(mCode));
        mEmail.addTextChangedListener(new TextChangeWatcher(mEmail));
    }

    class TextChangeWatcher implements TextWatcher {

        private EditText editText = null;

        public TextChangeWatcher(EditText editText) {
            this.editText = editText;
        }

        public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
        }


        public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
        }

        public void afterTextChanged(Editable editable) {
            if (editText.hasFocus()) {
                if (editText == mUsername) {
                    userStr = mUsername.getText().toString().trim();
                    if (FormatUtils.isUserName(userStr)) {
                        presenter.nameIsRegister(userStr, mLoginAnimImage);
                    } // else mUsername.setError("请输入3-12个数字、字母或汉字");
                    LogUtils.d("----登录注册界面  用户名：" + userStr, this.getClass());
                }
                if (editText == mEmail) {
                    emailStr = mEmail.getText().toString().trim();
                    if (FormatUtils.isEmail(emailStr) && emailStr.length() <= 31) {
                        presenter.emailIsRegister(emailStr, mLoginAnimImage);
                        LogUtils.d("----登录注册界面  邮箱：" + emailStr, this.getClass());
                    } // else mEmail.setError("邮箱格式错误");
                }
                if (editText == mPhone) {
                    phoneStr = mPhone.getText().toString().trim();
                    if (FormatUtils.isPhone(phoneStr)) {
                        presenter.phoneIsRegister(phoneStr);
                        LogUtils.d("----登录注册界面  手机号：" + phoneStr, this.getClass());
                    } // else mPhone.setError("手机号格式错误");
                }
                if (editText == mPassword) {
                    pwdStr = mPassword.getText().toString().trim();
//                    if (!FormatUtils.isPassword(pwdStr))
//                        mPassword.setError("请输入6-12个数字或字母");
                    LogUtils.d("----登录注册界面  密码：" + pwdStr, this.getClass());
                }
                if (editText == mResetPwd1) {
                    resetPwd1Str = mResetPwd1.getText().toString().trim();
//                    if (!FormatUtils.isPassword(resetPwd1Str))
//                        mResetPwd1.setError("请输入6-12个数字或字母");
                    LogUtils.d("----登录注册界面  重置密码：" + resetPwd1Str, this.getClass());
                }
                if (editText == mResetPwd2) {
                    resetPwd2Str = mResetPwd2.getText().toString().trim();
//                    if (!FormatUtils.isPassword(resetPwd2Str))
//                        mResetPwd2.setError("请输入6-12个数字或字母");
                    LogUtils.d("----登录注册界面  重置密码2：" + resetPwd2Str, this.getClass());
                }
                if (editText == mCode) {
                    codeStr = mCode.getText().toString().trim();
//                    if (!FormatUtils.isCheckCode(codeStr))
//                        mCode.setError("验证码格式错误");
                    LogUtils.d("----登录注册界面  短信验证码：" + codeStr, this.getClass());
                }
            }
        }
    }

    /**
     * 发送请求验证码
     *
     * @param phoneStr
     */
    private void SendCode(String phoneStr) {
        //接收验证码到手机
        BmobSMS.requestSMSCode(phoneStr, "detachment", new QueryListener<Integer>() {
            @Override
            public void done(Integer integer, BmobException e) {
                if (e == null) {
                    Log.e(TAG + "btn_get", String.valueOf(integer));
                    ToastColorfulUtils.success("验证码发送成功，请尽快验证");
                } else {
                    Log.e(TAG + "btn_get", e.toString());
                    ToastColorfulUtils.error("验证码发送失败");
                }
            }
        });
    }

    public void resetPwdCheckCode(final String phone, final String code) {
        if (phone != null && !FormatUtils.isPhone(phone)) {
            ToastColorfulUtils.error("手机号格式错误");
            return;
        }
        BmobSMS.verifySmsCode(phone, code, new UpdateListener() {
            @Override
            public void done(BmobException e) {
                if (e == null) {
                    LogUtils.d("----登录注册界面  短信验证码正确", this.getClass());
                    ToastColorfulUtils.success("短信验证码正确");
                    loginType = BRTQConstant.LOGIN_LAYOUT_RESET_PWD;
                    toggleResetPwd();
                } else {
                    LogUtils.d("----登录注册界面  短信验证码错误：" + String.valueOf(e), this.getClass());
                    ToastColorfulUtils.error("短信验证码错误");
                }
            }
        });
    }

    /**
     * 切换注册方式：手机、邮箱
     */
    private void toggleRegister() {
        switch (loginType) {
            case BRTQConstant.LOGIN_LAYOUT_REGISTER:
                mRegisterChangePhoneBtn.setBackgroundResource(R.drawable.shape_btn_corners_5dp);
                mRegisterChangeEmailBtn.setBackgroundColor(Color.TRANSPARENT);
                mEmailInput.setVisibility(View.GONE);
                mUsernameInput.setVisibility(View.VISIBLE);
                mPhoneCodeLayout.setVisibility(View.VISIBLE);
                break;
            case BRTQConstant.LOGIN_LAYOUT_REGISTER_EMAIL:
                mRegisterChangePhoneBtn.setBackgroundColor(Color.TRANSPARENT);
                mRegisterChangeEmailBtn.setBackgroundResource(R.drawable.shape_btn_corners_5dp);
                mEmailInput.setVisibility(View.VISIBLE);
                mUsernameInput.setVisibility(View.VISIBLE);
                mPhoneCodeLayout.setVisibility(View.GONE);
                break;
        }
    }

    /**
     * 切换重置密码方式：手机、邮箱
     */
    private void toggleResetPwd() {
        switch (loginType) {
            case BRTQConstant.LOGIN_LAYOUT_RESET_PWD_PHONE:
                mResetPwdChangePhoneBtn.setBackgroundResource(R.drawable.shape_btn_corners_5dp);
                mResetPwdChangeEmailBtn.setBackgroundColor(Color.TRANSPARENT);
                mEmailUsernamePwdLayout.setVisibility(View.GONE);
                mPhoneCodeLayout.setVisibility(View.VISIBLE);
                break;
            case BRTQConstant.LOGIN_LAYOUT_RESET_PWD_EMAIL:
                mResetPwdChangePhoneBtn.setBackgroundColor(Color.TRANSPARENT);
                mResetPwdChangeEmailBtn.setBackgroundResource(R.drawable.shape_btn_corners_5dp);
                mEmailUsernamePwdLayout.setVisibility(View.VISIBLE);
                mEmailInput.setVisibility(View.VISIBLE);
                mPhoneCodeLayout.setVisibility(View.GONE);
                break;
            case BRTQConstant.LOGIN_LAYOUT_RESET_PWD:
                mResetPwdLayout.setVisibility(View.VISIBLE);
                mResetPwdTopLayout.setVisibility(View.GONE);
                mEmailUsernamePwdLayout.setVisibility(View.GONE);
                mPhoneCodeLayout.setVisibility(View.GONE);
                mResetPwdSendMsgBtn.setVisibility(View.GONE);
                mResetPwdSureBtn.setVisibility(View.VISIBLE);
                break;
        }
    }

    /**
     * 切换登录方式：手机、邮箱
     */
    private void toggleLogin() {
        switch (loginType) {
            case BRTQConstant.LOGIN_LAYOUT_LOGIN:
                mLoginChangePhoneBtn.setBackgroundResource(R.drawable.shape_btn_corners_5dp);
                mLoginChangeEmailBtn.setBackgroundColor(Color.TRANSPARENT);
                mEmailInput.setVisibility(View.GONE);
                mUsernameInput.setVisibility(View.VISIBLE);
                break;
            case BRTQConstant.LOGIN_LAYOUT_LOGIN_EMAIL:
                mLoginChangePhoneBtn.setBackgroundColor(Color.TRANSPARENT);
                mLoginChangeEmailBtn.setBackgroundResource(R.drawable.shape_btn_corners_5dp);
                mEmailInput.setVisibility(View.VISIBLE);
                mUsernameInput.setVisibility(View.GONE);
                break;
        }
    }

    /**
     * 切换登录、注册、重置密码
     */
    private void toggleType() {
        switch (loginType) {
            case BRTQConstant.LOGIN_LAYOUT_LOGIN:
                setTextNothing();
                toolbarTitle.setText(R.string.login);
                mResetPwdLayout.setVisibility(View.GONE);
                mResetPwdSureBtn.setVisibility(View.GONE);
                mLoginChangePhoneBtn.setBackgroundResource(R.drawable.shape_btn_corners_5dp);
                mLoginChangeEmailBtn.setBackgroundColor(Color.TRANSPARENT);
                mLoginTopLayout.setVisibility(View.VISIBLE);
                mRegisterTopLayout.setVisibility(View.GONE);
                mResetPwdTopLayout.setVisibility(View.GONE);
                mChangeLoginBtn.setVisibility(View.GONE);
                mChangeRegisterBtn.setVisibility(View.VISIBLE);
                mChangeResetPwdBtn.setVisibility(View.VISIBLE);
                mLoginBtn.setVisibility(View.VISIBLE);
                mRegisterBtn.setVisibility(View.GONE);
                mResetPwdSendMsgBtn.setVisibility(View.GONE);
                mEmailUsernamePwdLayout.setVisibility(View.VISIBLE);
                mEmailInput.setVisibility(View.GONE);
                mUsernameInput.setVisibility(View.VISIBLE);
                mPasswordInput.setVisibility(View.VISIBLE);
                mPhoneCodeLayout.setVisibility(View.GONE);
                break;
            case BRTQConstant.LOGIN_LAYOUT_REGISTER:
                setTextNothing();
                toolbarTitle.setText(R.string.register);
                mResetPwdLayout.setVisibility(View.GONE);
                mResetPwdSureBtn.setVisibility(View.GONE);
                mRegisterChangePhoneBtn.setBackgroundResource(R.drawable.shape_btn_corners_5dp);
                mRegisterChangeEmailBtn.setBackgroundColor(Color.TRANSPARENT);
                mLoginTopLayout.setVisibility(View.GONE);
                mRegisterTopLayout.setVisibility(View.VISIBLE);
                mResetPwdTopLayout.setVisibility(View.GONE);
                mChangeLoginBtn.setVisibility(View.VISIBLE);
                mChangeRegisterBtn.setVisibility(View.GONE);
                mChangeResetPwdBtn.setVisibility(View.VISIBLE);
                mLoginBtn.setVisibility(View.GONE);
                mRegisterBtn.setVisibility(View.VISIBLE);
                mResetPwdSendMsgBtn.setVisibility(View.GONE);
                mEmailUsernamePwdLayout.setVisibility(View.VISIBLE);
                mEmailInput.setVisibility(View.GONE);
                mUsernameInput.setVisibility(View.VISIBLE);
                mPasswordInput.setVisibility(View.VISIBLE);
                mPhoneCodeLayout.setVisibility(View.VISIBLE);
                break;
            case BRTQConstant.LOGIN_LAYOUT_RESET_PWD_PHONE:
                setTextNothing();
                toolbarTitle.setText(R.string.reset_pwd);
                mResetPwdLayout.setVisibility(View.GONE);
                mResetPwdSureBtn.setVisibility(View.GONE);
                mResetPwdChangePhoneBtn.setBackgroundResource(R.drawable.shape_btn_corners_5dp);
                mResetPwdChangeEmailBtn.setBackgroundColor(Color.TRANSPARENT);
                mLoginTopLayout.setVisibility(View.GONE);
                mRegisterTopLayout.setVisibility(View.GONE);
                mResetPwdTopLayout.setVisibility(View.VISIBLE);
                mChangeLoginBtn.setVisibility(View.VISIBLE);
                mChangeRegisterBtn.setVisibility(View.VISIBLE);
                mChangeResetPwdBtn.setVisibility(View.GONE);
                mLoginBtn.setVisibility(View.GONE);
                mRegisterBtn.setVisibility(View.GONE);
                mResetPwdSendMsgBtn.setVisibility(View.VISIBLE);
                mEmailUsernamePwdLayout.setVisibility(View.GONE);
                mEmailInput.setVisibility(View.GONE);
                mUsernameInput.setVisibility(View.GONE);
                mPasswordInput.setVisibility(View.GONE);
                mPhoneCodeLayout.setVisibility(View.VISIBLE);
                break;
        }
    }

    private void setTextNothing() {
        mUsername.setText("");
        mEmail.setText("");
        mPassword.setText("");
        mPhone.setText("");
        mCode.setText("");
        /*mUsername.setError(null);
        mEmail.setText(null);
        mPassword.setText(null);
        mPhone.setText(null);
        mCode.setText(null);*/
    }

    /**
     * 验证码按钮倒计时
     */
    private CountDownTimer timer = new CountDownTimer(60000, 1000) {
        @SuppressLint("ResourceAsColor")
        @Override
        public void onTick(long millisUntilFinished) {
            mSendCodeBtn.setEnabled(false);
            mSendCodeBtn.setText((millisUntilFinished / 1000) + "s");
            mSendCodeBtn.setTextColor(R.color.black);
        }

        @Override
        public void onFinish() {
            mSendCodeBtn.setEnabled(true);
            mSendCodeBtn.setText("发送验证码");
        }
    };

}
